Skip to content

Update the format of selected state and propagate it to the treeview#1817

Merged
charisk merged 3 commits intomainfrom
charisk/selected-db-state
Dec 1, 2022
Merged

Update the format of selected state and propagate it to the treeview#1817
charisk merged 3 commits intomainfrom
charisk/selected-db-state

Conversation

@charisk
Copy link
Copy Markdown
Contributor

@charisk charisk commented Dec 1, 2022

The format we had initially decide on was unfortunately not ideal in terms of implementation so we're changing it to be more explicit. In general we don't expect users to manually define that state in the config, apart from some exceptional cases. The configuration schema has been updated to help in those rare cases. See commit 943c547

We then read the configuration state and propagate selection all the way to the tree view items. See commit 7b54b6c. We currently don't do anything with that, but in a following PR we'll use that information to show the relevant icons and actions.

Checklist

N/A:

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

This format will make implementation much simpler than having to parse JSON paths.
@charisk charisk added the secexp label Dec 1, 2022
@charisk charisk requested review from a team as code owners December 1, 2022 10:28
Copy link
Copy Markdown
Contributor

@shati-patel shati-patel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for doing this ⚡

Comment on lines +81 to +111
export function isRemoteSystemDefinedListDbItem(
dbItem: DbItem,
): dbItem is RemoteSystemDefinedListDbItem {
return dbItem.kind === DbItemKind.RemoteSystemDefinedList;
}

export function isRemoteUserDefinedListDbItem(
dbItem: DbItem,
): dbItem is RemoteUserDefinedListDbItem {
return dbItem.kind === DbItemKind.RemoteUserDefinedList;
}

export function isRemoteOwnerDbItem(
dbItem: DbItem,
): dbItem is RemoteOwnerDbItem {
return dbItem.kind === DbItemKind.RemoteOwner;
}

export function isRemoteRepoDbItem(dbItem: DbItem): dbItem is RemoteRepoDbItem {
return dbItem.kind === DbItemKind.RemoteRepo;
}

export function isLocalListDbItem(dbItem: DbItem): dbItem is LocalListDbItem {
return dbItem.kind === DbItemKind.LocalList;
}

export function isLocalDatabaseDbItem(
dbItem: DbItem,
): dbItem is LocalDatabaseDbItem {
return dbItem.kind === DbItemKind.LocalDatabase;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 30 lines are only created for tests. Isn't that a huge code smell? Can't we solve the problem differently? The two isLocal... are not used at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can definitely solve this differently - it requires checking the dbItem.kind and then casting the item to the relevant type, which is a little bit more fiddly that simply using type guards.

We could move the code somewhere else too since it's just for tests but I think that would make it harder to find and much more likely for this code to get duplicated elsewhere. We could also only implement what is needed (and don't include the type guards for local dbs) but to me that feels incomplete.

And despite this being 30 LoC, it's 30 lines of straight-forward code.

So in general I think you have the right reactions seeing this code, but I think this is a case where it's ok to break the "rules" a bit. And the db-item module comes with a more complete interface.

Comment thread extensions/ql-vscode/src/databases/config/db-config.ts
Comment thread extensions/ql-vscode/src/databases/config/db-config.ts
Comment thread extensions/ql-vscode/src/databases/config/db-config.ts
@charisk charisk merged commit 6d1b5ab into main Dec 1, 2022
@charisk charisk deleted the charisk/selected-db-state branch December 1, 2022 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants